package com.le.tester.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * currentTime:2022/3/11 10:45
 * description:是不是同构的字符串
 */
public class Isomorphic {
    public boolean isIsomorphic(String s, String t) {

        int sLength = s.length();
        Map<Character, Object> sMap = new HashMap<>();
        Map<Character, Object> tMap = new HashMap<>();
        for (int i = 0; i < sLength; i++) {
            char charAtS = s.charAt(i);
            char charAtT = t.charAt(i);

            if ((sMap.containsKey(charAtS) && !(sMap.get(charAtS).equals(charAtT)))
                    || (tMap.containsKey(charAtT) && !(tMap.get(charAtT).equals(charAtS)))) {
                return false;
            }

            sMap.put(charAtS, charAtT);
            tMap.put(charAtT, charAtS);
        }

        return true;
    }

    public static void main(String[] args) {
        Isomorphic isomorphic = new Isomorphic();
        System.out.println(isomorphic.isIsomorphic("keep", "book"));
    }
}
